#include <windows.h>
HWND myCreateBox(HWND hwnd, int id, char* type, char* s,
int x, int y, int width, int height)
{ HWND h;
char typechar = type[0];
DWORD styleex;
DWORD style;
char* classname;
switch ( typechar )
{
case 'f': case 'F':
styleex = WS_EX_WINDOWEDGE;
style = WS_CHILD | WS_VISIBLE | SS_BLACKFRAME;
classname = "STATIC";
break;
case 's': case 'S':
styleex = WS_EX_STATICEDGE;
style = WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX;
classname = "STATIC";
break;
case 'e': case 'E':
{ styleex = WS_EX_CLIENTEDGE;
style = WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;
char* c = type;
while( (*c != '1') && (*c != 0) ) ++c;
if (*c==0) style |= ES_MULTILINE | ES_AUTOVSCROLL;
classname = "EDIT";
}
break;
case 'l': case 'L':
styleex = WS_EX_CLIENTEDGE;
style = WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_NOTIFY;
classname = "LISTBOX";
break;
default:
MessageBox(hwnd, "unrecognised box type in myCreateBox.", "Error", MB_OK | MB_ICONERROR);
}
h = CreateWindowEx(styleex, classname, "", style, x,y,width,height,
hwnd, (HMENU) id, GetModuleHandle(NULL), NULL);
if (h == NULL)
{ MessageBox(hwnd, "myCreateBox could not create box.", "Error", MB_OK | MB_ICONERROR);
return h;
}
HFONT hfont;
hfont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
SendMessage(h, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(FALSE, 0));
switch ( typechar )
{
case 'f': case 'F': break;
case 's': case 'S': case 'e': case 'E':
SendMessage(h, WM_SETTEXT, 0, (LPARAM) s); break;
case 'l': case 'L':
SendMessage(h, LB_ADDSTRING, 0, (LPARAM) s); break;
}
return h;
}